df_rep1 <- final %>% filter(pid2 == 'Republican') %>% filter(days <= 150)
df_dem1 <- final %>% filter(pid2 == 'Democrat') %>% filter(days <= 150)

x1 <- ggplot()+
  geom_smooth(data = df_rep1 %>% filter(days < 1), aes(days, violence_range), method = 'loess', color = '#cc6677', fill = "#cc6677")+
  geom_smooth(data = df_rep1 %>% filter(days > -1), aes(days, violence_range), method = 'loess', color = '#cc6677', fill = "#cc6677")+
  geom_smooth(data = df_dem1 %>% filter(days < 1), aes(days, violence_range), method = 'loess', color = '#56B4E9', fill = "#56B4E9")+
  geom_smooth(data = df_dem1 %>% filter(days > -1), aes(days, violence_range), method = 'loess', color = '#56B4E9', fill = "#56B4E9")+
  theme_bw()+
  geom_vline(xintercept = 0, color = 'red', linetype=2)+
  coord_cartesian(ylim = c(0,0.4))+
  scale_x_continuous(breaks = seq(-50,150,10))+
  xlab('Days before/after 2022 Election')+
  ylab('Support Political Violence')

x2 <- ggplot()+
  geom_smooth(data = df_rep1 %>% filter(days < 1), aes(days, norms_range), method = 'loess', color = '#cc6677', fill = "#cc6677")+
  geom_smooth(data = df_rep1 %>% filter(days > -1), aes(days, norms_range), method = 'loess', color = '#cc6677', fill = "#cc6677")+
  geom_smooth(data = df_dem1 %>% filter(days < 1), aes(days, norms_range), method = 'loess', color = '#56B4E9', fill = "#56B4E9")+
  geom_smooth(data = df_dem1 %>% filter(days > -1), aes(days, norms_range), method = 'loess', color = '#56B4E9', fill = "#56B4E9")+
  theme_bw()+
  geom_vline(xintercept = 0, color = 'red', linetype=2)+
  coord_cartesian(ylim = c(0.2,0.6))+
  scale_x_continuous(breaks = seq(-50,150,10))+
  xlab('Days before/after 2022 Election')+
  ylab('Support Norm Violations')

x3 <- ggplot()+
  geom_smooth(data = df_rep1 %>% filter(days < 1), aes(days, affpol), method = 'loess', color = '#cc6677', fill = "#cc6677")+
  geom_smooth(data = df_rep1 %>% filter(days > -1), aes(days, affpol), method = 'loess', color = '#cc6677', fill = "#cc6677")+
  geom_smooth(data = df_dem1 %>% filter(days < 1), aes(days, affpol), method = 'loess', color = '#56B4E9', fill = "#56B4E9")+
  geom_smooth(data = df_dem1 %>% filter(days > -1), aes(days, affpol), method = 'loess', color = '#56B4E9', fill = "#56B4E9")+
  theme_bw()+
  geom_vline(xintercept = 0, color = 'red', linetype=2)+
  coord_cartesian(ylim = c(20,80))+
  scale_x_continuous(breaks = seq(-50,150,10))+
  xlab('Days before/after 2022 Election')+
  ylab('Affective Polarization')+
  scale_color_manual(values=c("#cc6677", "#56B4E9"),
                     labels=c('Republican', 'Democrat'))+
  scale_fill_manual(values=c("#cc6677", "#56B4E9"),
                    labels=c('Republican', 'Democrat'))+
  theme(legend.position = 'bottom')+
  labs(fill = "Political Interest", color = 'Political Interest')

final_figure_win <- suppressMessages(ggpubr::ggarrange(x1,x2,x3, ncol = 1))
suppressMessages(print(final_figure_win))
#ggsave(final_figure_win, file = 'final_figure_win.png', units = 'in', height = 8, width = 10)